#pragma once

#include "register_value.h"

template <size_t SIZE, typename register_t = typename register_value<SIZE>>
class base_register {
	using value_t = typename register_t::value_t;

public:
	template <typename T>
	constexpr base_register(T value): _value{ static_cast<value_t>(value) } {}

	constexpr size_t size() const& { return SIZE; }

	constexpr value_t read() const& { return _value; }

	constexpr bit read(size_t pos) const& {
		return read() & (value_t(bit::T) << pos);
	}

	template <typename T>
	constexpr void write(T value) & {
		_value = static_cast<value_t>(value);
	}

	constexpr void set(size_t pos) & {
		_value |= value_t(bit::T) << pos;
	}

	constexpr void reset(size_t pos) & {
		_value &= ~(value_t(bit::T) << pos);
	}

private:
	value_t _value;
};